package com.gzs.learn.springcloud.config.hotconfig;

import java.util.concurrent.Executor;
import com.alibaba.nacos.api.config.listener.Listener;
import com.gzs.learn.springcloud.common.BeanUtil;
import com.gzs.learn.springcloud.common.JsonUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HotCofnigListener implements Listener {
    private Object holder;
    private Class<?> type;

    public HotCofnigListener(Object holder, Class<?> type) {
        this.holder = holder;
        this.type = type;
    }

    @Override
    public Executor getExecutor() {
        return null;
    }

    @Override
    public void receiveConfigInfo(String configInfo) {
        log.info("recv nacos hot config changed [{}],type [{}]", configInfo, type.getName());
        BeanUtil.copyProperties(JsonUtil.parseObject(configInfo, type), holder);
    }
}
